//
//  SystemFoundationViewController.m
//  Effective Objective-C 2.0
//
//  Created by 周成龙 on 2018/2/1.
//  Copyright © 2018年 周成龙. All rights reserved.
//

#import "SystemFoundationViewController.h"

@interface SystemFoundationViewController ()

@end

@implementation SystemFoundationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 多用块枚举，少用for循环
    [self moewEnumratorLessFor];
    
}
// 多用块枚举，少用for循环
- (void)moewEnumratorLessFor {
    
    NSLog(@"=========== NSEnumerator ==============");
    NSArray *anArray = @[@"1", @"2", @"3"];
    NSEnumerator *enumratorArr = [anArray objectEnumerator];
    // [anArray reverseObjectEnumerator];反转
    NSString *arrObj;
    while ((arrObj = [enumratorArr nextObject]) != nil) {
        NSLog(@"%@", arrObj);
    }
    NSLog(@"--------------------");
    NSDictionary *dict =@{@"name": @"zs", @"age":@(18)};
    NSEnumerator *enumratorDict = [dict keyEnumerator];
//    [dict objectEnumerator];
    NSString *key;
    while ((key = [enumratorDict nextObject]) != nil) {
        NSLog(@"%@:%@", key, dict[key]);
    }
    NSLog(@"--------------------");
    NSSet *set = [NSSet setWithArray:anArray];
    NSEnumerator *enumratorSet = [set objectEnumerator];
    NSString *setObj;
    while ((setObj = [enumratorSet nextObject]) != nil) {
        NSLog(@"%@", setObj);
    }
    
    // 快速遍历
    NSLog(@"=========== 快速遍历 ==============");
    for (NSString *str in anArray) {
        NSLog(@"%@", str);
    }
    
//    NSUInteger idx = [anArray countByEnumeratingWithState:<#(nonnull NSFastEnumerationState *)#> objects:<#(id  _Nullable __unsafe_unretained * _Nonnull)#> count:<#(NSUInteger)#>];
//    NSLog(@"idx:%lu", idx);
    
    // 基于 块 遍历方式
    NSLog(@"=========== 基于 块 遍历方式 ==============");
    [anArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
    }];
    [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        
    }];
    [set enumerateObjectsUsingBlock:^(id  _Nonnull obj, BOOL * _Nonnull stop) {
        
    }];
}


@end
